//
//  TLTweetToolBar.m
//  Coding_iOS
//
//  Created by taolei-mac on 2017/11/29.
//  Copyright © 2017年 com.lianchuan. All rights reserved.
//

#import "TLTweetToolBar.h"
#import "TLTweet.h"

@interface TLTweetToolBar ()

/** 点赞按钮 */
@property (nonatomic, weak) UIButton *likedButton;
/** 转发按钮 */
@property (nonatomic, weak) UIButton *rewardButton;
/** 评论按钮 */
@property (nonatomic, weak) UIButton *commentButton;

@end

@implementation TLTweetToolBar

- (void)setTweet:(TLTweet *)tweet
{
    _tweet = tweet;
    [self.likedButton setTitle:[NSString stringWithFormat:@"%zd", tweet.likes] forState:UIControlStateNormal];
    [self.likedButton.titleLabel sizeToFit];
    self.likedButton.frame = CGRectMake(20, 5, self.likedButton.currentImage.size.width + self.likedButton.titleLabel.width, 20);
    
    [self.rewardButton setTitle:[NSString stringWithFormat:@"%zd", tweet.rewards] forState:UIControlStateNormal];
    [self.rewardButton.titleLabel sizeToFit];
    self.rewardButton.frame = CGRectMake(CGRectGetMaxX(self.likedButton.frame) + 20, 5, self.rewardButton.currentImage.size.width + self.rewardButton.titleLabel.width, 20);
    
    [self.commentButton setTitle:[NSString stringWithFormat:@"%zd", tweet.comments] forState:UIControlStateNormal];
    [self.commentButton.titleLabel sizeToFit];
    CGFloat buttonW = self.commentButton.currentImage.size.width + self.commentButton.titleLabel.width;
    self.commentButton.frame = CGRectMake(TLScreenW - 20 - buttonW, 5, buttonW, 20);
}

- (instancetype)init
{
    self = [super init];
    if(self){
        
        [self addSubViews];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self){
        
        [self addSubViews];
    }
    return self;
}


/**
 *  添加子控件
 */
- (void)addSubViews
{
    self.backgroundColor = [UIColor whiteColor];
    // 添加点赞按钮
    UIButton *likedButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [likedButton setImage:[UIImage originImageWithName:@"tweet_btn_like"] forState:UIControlStateNormal];
    [likedButton setTitleColor:[UIColor colorWithHexString:@"0x76808E"] forState:UIControlStateNormal];
    likedButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [likedButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 5)];
    [self addSubview:likedButton];
    self.likedButton = likedButton;
    
    // 添加转发按钮
    UIButton *rewardButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [rewardButton setImage:[UIImage originImageWithName:@"tweet_btn_reward"] forState:UIControlStateNormal];
    [rewardButton setTitleColor:[UIColor colorWithHexString:@"0x76808E"] forState:UIControlStateNormal];
    rewardButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [rewardButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 5)];
    [self addSubview:rewardButton];
    self.rewardButton = rewardButton;
    
    // 添加评论按钮
    UIButton *commentButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [commentButton setImage:[UIImage originImageWithName:@"tweet_btn_comment"] forState:UIControlStateNormal];
    [commentButton setTitleColor:[UIColor colorWithHexString:@"0x76808E"] forState:UIControlStateNormal];
    commentButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [commentButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 5)];
    [self addSubview:commentButton];
    self.commentButton = commentButton;
}

@end
